<?php

/*
 * 控制器的基类,包含设置参数方法
 * and open the template in the editor.
 */
 class Basecontroll
{
     private $_pars=array();
     protected $upload;
     public function __construct() {
         $this->upload=  UploadFile::getInstance();
     }
     public function getThumb($picpath,$style){
         global $_G;
         $imagepath="";
         if(isset($_G["upload_image"]["image_path"])){
             $imagepath=$_G["upload_image"]["image_path"];
         }
         
         if(stripos($picpath, $imagepath)!==FALSE){
             $picpath=str_replace($imagepath, "", $picpath);
         }
      
         return $this->upload->getImageUrl($picpath,$style);
     }
     //设置参数方法
     public function setParams($pars=  array())
     {
         $this->_pars=$pars;
     }

     //载入数据库表对象，参数1：表名
     protected function load($table_name){
      
         return new MysqlDB($table_name);
     }
     //当没传递控制器和方法参数时,返回的默认页面.
     public function defaultmethod()
     {
         //echo '网站默认页面';
         //$log=  Logclass::getInstance();
      //  $log->writeline('ddd');
       // var_dump( $log->readline(1));
       //$hook=  Wjphooks::getInstance();
       Temp::display();
         
         
     }
     //清除cookie信息
     public function clearCookie($key=""){
         setcookie($key, "", time()-3600);
     }
    //取得cookie信息
    public function getCookie($key=""){
        return isset($_COOKIE[$key])?unserialize(stripslashes($_COOKIE[$key])):array();
    }



    //当访问的方法或者控制器不存在时,返回404页面给用户
     public function page404()
     {
        // echo '404页面';
     }
     //做跳转
     public function showmessage($msg,$type = "error",$url='',$timeout=1000){
         if($url!=''){
         $script="<script>setTimeout(function(){window.location.href='{$url}';},{$timeout});</script>";
         $javascript=$url;
         }else{
         $javascript="javascript:void(0);";
         $script="<script>setTimeout(function(){window.history.go(-1);},{$timeout});</script>"; 
         }
         $html="<meta name='viewport' content='width=device-width, initial-scale=1'><div style='float: left;position:relative;min-height:300px;left:50%;margin:30px -140px;padding:10px 10px;width:260px;box-shadow: rgba(0,0,0,.27) 0 1px 3px,#DCDCDC 0 1px 0,#DDD 0 -1px 0;border-radius: 8px;color:#3c763d;font-size: 15px;font-family: Microsoft yahei;'><p style='color:red;'>{$type}:</p><p style='text-align:center;'>{$msg}</p><p style='position:absolute;bottom:0px;width:100%;text-align:center;left:0px;'><a href='{$javascript}' style='text-decoration: none;color:red;'>点击返回</a></p></div>";
        
         echo $html.$script;
     }
        
    
}
?>
